//
//  DbManage.m
//  02-FMDB的简单使用
//
//  Created by Jiafei Wei on 16/7/24.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "DbManage.h"
#import "FMDB.h"
#import "TContact.h"
#import "TContactGroup.h"
#import "NewContactDao.h"
#import "ContactPersonInfo.h"
#import "MarkInfo.h"
#import "InterceptInfo.h"
@interface DbManage()
@property (nonatomic, strong) FMDatabase *db;
@end

@implementation DbManage

static DbManage *instance;
//单例模式
+(DbManage *)shareDbManage{
    @synchronized (self) {
        if (instance==nil) {
            instance = [[DbManage alloc]init];
            [instance openDB];//打开数据库
        }
    }
    return instance;
}

-(void)openDB{
    // Do any additional setup after loading the view, typically from a nib.
    NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    // 拼接文件名
    NSString *filePath = [cachePath stringByAppendingPathComponent:@"anlang.sqlite"];
    // 创建一个数据库的实例,仅仅在创建一个实例，并会打开数据库
    FMDatabase *db = [FMDatabase databaseWithPath:filePath];
    _db = db;
    // 打开数据库
    BOOL flag = [db open];
    if (flag) {
        NSLog(@"打开成功");
    }else{
        NSLog(@"打开失败");
    }
    // 创建数据库表
    // 数据库操作：插入，更新，删除都属于update
    // 参数：sqlite语句
    BOOL flag1 = [db executeUpdate:@"create table if not exists remind_things (id integer primary key autoincrement,title text,doTime text,doCircle text,createTime text,remark text,only text,isRmeind text);"];
    if (flag1) {
        NSLog(@"创建成功");
    }else{
        NSLog(@"创建失败");
    }
    
    BOOL flag2 = [db executeUpdate:@"create table if not exists stock_code (id integer primary key autoincrement,name text,stockcode text,upNumber text,downNumber text,fallNumber text,increaseNumber text,isUpNumber text,isDownNumber text,isFallNumber text,isIncreaseNumber text,isHaving text);"];
    
    if (flag2) {
        NSLog(@"创建成功");
    }else{
        NSLog(@"创建失败");
    }
    
    BOOL flag3 = [db executeUpdate:@"create table if not exists contact_info (id integer primary key autoincrement,reallyId text,phone text,name text,contactgroup text);"];
    
    if (flag3) {
        NSLog(@"flag3==创建成功");
    }else{
        NSLog(@"flag3===创建失败");
    }
    BOOL flag4 = [db executeUpdate:@"create table if not exists new_contact_info (id integer primary key autoincrement,contactId integer,displayName text,phoneNum text,sortKey text,photoId integer,lookUpKey text,selected integer,formattedNumber text,pinyin text,version text,note text,group_id integer,group_name text);"];
    if (flag4) {
        NSLog(@"flag4==创建成功");
    }else{
        NSLog(@"flag4===创建失败");
    }
    
    BOOL flag5 = [db executeUpdate:@"create table if not exists person_info (id integer primary key autoincrement,user_id text,head_pic text,nickname text,sign text,sex text,other text,address text);"];
    
    if (flag5) {
        NSLog(@"flag5==创建成功");
    }else{
        NSLog(@"flag===创建失败");
    }
    BOOL flag6 = [db executeUpdate:@"create table if not exists mark_info (id integer primary key autoincrement,number text,mark text,staus text,time text,isSendTo integer,isDelete integer);"];
    
    if (flag6) {
        NSLog(@"flag6==创建成功");
    }else{
        NSLog(@"flag6===创建失败");
    }

    BOOL flag7 = [db executeUpdate:@"create table if not exists intercept_info_a (id integer primary key autoincrement,callcontent text,type text,callFrom text,callTo text,mark text,attribution text,time text,isRead text);"];
    
    //BOOL flag7 = [db executeUpdate:@"create table if not exists intercept_info_a (id integer primary key autoincrement,content text,type text,from text,to text,mark text,attribution text,time text,isRead text);"];
    
    if (flag7) {
        NSLog(@"flag7==创建成功");
    }else{
        NSLog(@"flag7===创建失败");
    }
  }
-(void)insert:(RemingThings *)model{//插入
    BOOL flag = [_db executeUpdate:@"insert into remind_things (title,doTime,doCircle,createTime,remark,only,isRmeind) values (?,?,?,?,?,?,?)",model.title,model.doTime,model.doCircle,model.createTime,model.remark,model.only,model.isRmeind];
    if (flag) {
        NSLog(@"success");
    }else{
        NSLog(@"failure");
    }
}

-(NSMutableArray *)query{//查询
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from remind_things"]; // 从结果集里面往下找
    while ([result next]) {
        RemingThings *d =[[RemingThings alloc]init];
        d.id= [result intForColumn:@"id"];
        d.title= [result stringForColumn:@"title"];
        d.doTime = [result stringForColumn:@"doTime"];
        d.doCircle= [result stringForColumn:@"doCircle"];
        d.createTime = [result stringForColumn:@"createTime"];
        d.remark= [result stringForColumn:@"remark"];
        d.only = [result stringForColumn:@"only"];
        d.isRmeind =[result stringForColumn:@"isRmeind"];
        [arry addObject:d];
    }
    [result close];
    return arry;
}

-(void)deleteData:(RemingThings *)model{
    //根据id去删除
    NSNumber *id =[NSNumber numberWithInt:model.id];
    BOOL flag = [_db executeUpdate:@"delete from remind_things where id=?",id];
    if (flag) {
        NSLog(@"success");
    }else{
        NSLog(@"failure");
    }
}

-(void)update:(RemingThings *)model{//更新数据库的操作
    //你吗的少了个逗号啊
    NSNumber *id =[NSNumber numberWithInt:model.id];
    BOOL flag = [_db executeUpdate:@"update remind_things set title =?,doTime=?,doCircle=?,createTime=?,remark=?,only=?,isRmeind=? where id=?",model.title,model.doTime,model.doCircle,model.createTime,model.remark,model.only,model.isRmeind,id];
    if (flag) {
        NSLog(@"success");
    }else{
        NSLog(@"failure");
    }
}
//删除集合的数据
-(void)deleteThingsArrary:(NSMutableArray *)arry{
    for (RemingThings* t in arry) {
        [self deleteData:t];
    }
}
-(void)insertStock:(StockCode *)code{
    BOOL flag = [_db executeUpdate:@"insert into stock_code (name,stockcode,upNumber,downNumber,fallNumber,increaseNumber,isUpNumber,isDownNumber,isFallNumber,isIncreaseNumber,isHaving) values (?,?,?,?,?,?,?,?,?,?,?)",code.name,code.stockcode,code.upNumber,code.downNumber,code.fallNumber,code.increaseNumber,code.isUpNumber,code.isDownNumber,code.isFallNumber,code.isIncreaseNumber,code.isHaving];
    if (flag) {
        NSLog(@"insertStock＝＝＝＝＝success");
    }else{
        NSLog(@"failure");
    }

}
-(void)insertStockByArray:(NSMutableArray *)arry{
    for (StockCode* s in arry) {
        [self insertStock:s];
    }
}
-(NSMutableArray *)queryStock{
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from stock_code"]; // 从结果集里面往下找
    while ([result next]) {
        StockCode *d =[[StockCode alloc]init];
        d.id= [result intForColumn:@"id"];
        d.name= [result stringForColumn:@"name"];
        d.stockcode = [result stringForColumn:@"stockcode"];
        d.upNumber= [result stringForColumn:@"upNumber"];
        d.downNumber = [result stringForColumn:@"downNumber"];
        d.fallNumber= [result stringForColumn:@"fallNumber"];
        d.increaseNumber = [result stringForColumn:@"increaseNumber"];
        d.isUpNumber =[result stringForColumn:@"isUpNumber"];
        
        d.isDownNumber = [result stringForColumn:@"isDownNumber"];
        d.isFallNumber= [result stringForColumn:@"isFallNumber"];
        d.isIncreaseNumber = [result stringForColumn:@"isIncreaseNumber"];
        d.isHaving =[result stringForColumn:@"isHaving"];
        [arry addObject:d];
    }
    [result close];
    return arry;
}
-(void)deleteStock:(StockCode *)code{
    //根据id去删除
    NSNumber *id =[NSNumber numberWithInt:code.id];
    BOOL flag = [_db executeUpdate:@"delete from stock_code where id=?",id];
    if (flag) {
        NSLog(@"success");
    }else{
        NSLog(@"failure");
    }
}
-(void)updateStock:(StockCode *)code{
    //你吗的少了个逗号啊
    NSNumber *id =[NSNumber numberWithInt:code.id];
    BOOL flag = [_db executeUpdate:@"update stock_code set name =?,stockcode=?,upNumber=?,downNumber=?,fallNumber=?,increaseNumber=?,isUpNumber=?,isDownNumber=?,isFallNumber=?,isIncreaseNumber=?,isHaving=? where id=?",code.name,code.stockcode,code.upNumber,code.downNumber,code.fallNumber,code.increaseNumber,code.isUpNumber,code.isDownNumber,code.isFallNumber,code.isIncreaseNumber,code.isHaving,id];
    if (flag) {
        NSLog(@"success");
    }else{
        NSLog(@"failure");
    }
}

-(void)updateStockByName:(StockCode *)code{
    NSNumber *id =[NSNumber numberWithInt:code.id];
    BOOL flag = [_db executeUpdate:@"update stock_code set id=? where name=?",code.name];
    if (flag) {
        NSLog(@"updateStockByName======success");
    }else{
        NSLog(@"failure");
    }
}
-(void)deleteStockArrary:(NSMutableArray *)arry{
    for (StockCode* s in arry) {
        [self deleteStock:s];
    }
}
//开始做数据处理操作
//stockcode
-(void)deleteStockByCode:(NSString *)name{//其实都是唯一的
    BOOL flag = [_db executeUpdate:@"delete from stock_code where name=?",name];
    if (flag) {
        NSLog(@"deleteStockByCode＝＝＝＝＝＝＝success");
    }else{
        NSLog(@"failure");
    }
}

-(void)deletAllStock{
    BOOL flag = [_db executeUpdate:@"delete from stock_code"];
    if (flag) {
        NSLog(@"deletAllStock＝＝＝＝＝＝＝success");
    }else{
        NSLog(@"failure");
    }
}

-(void)insertConatctArray:(NSMutableArray *)contactArray{
    for (TContact *t in contactArray) {
        BOOL flag = [_db executeUpdate:@"insert into contact_info (reallyId,phone,name,contactgroup) values (?,?,?,?)",t.reallyId,t.phone,t.name,t.group];
        if (flag) {
            NSLog(@"success");
        }else{
            NSLog(@"failure");
        }
    }
}

-(void)updateConatct:(TContact *)contact{
      //NSNumber *reallyId =[NSNumber numberWithInt:contact.reallyId];
    BOOL flag = [_db executeUpdate:@"update contact_info set phone =?,name=?,contactgroup=?where reallyId=?",contact.phone,contact.name,contact.group,contact.reallyId];
    if (flag) {
        NSLog(@"updateConatct=====d=a=d=ad=ad=ad=ad=success");
    }else{
        NSLog(@"failure");
    }

}
-(void)updateConatctArray:(NSMutableArray *)contactArray{
    for (TContact *t in contactArray) {
        [self updateConatct:t];
    }
}
-(void)deleteConatctArray:(NSMutableArray *)contactArray{
    for (TContact *t in contactArray) {
        //NSNumber *id =[NSNumber numberWithInt:t.reallyId];
        BOOL flag = [_db executeUpdate:@"delete from contact_info where reallyId=?",t.reallyId];
        if (flag) {
            NSLog(@"success");
        }else{
            NSLog(@"failure");
        }
    }
}
//返回查询的联系人
-(NSMutableArray *)queryConatctArray{
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from contact_info"];
    while ([result next]) {
        TContact *d =[[TContact alloc]init];
        d.id= [result intForColumn:@"id"];
        d.reallyId= [result stringForColumn:@"reallyId"];
        d.phone = [result stringForColumn:@"phone"];
        d.name= [result stringForColumn:@"name"];
        d.group = [result stringForColumn:@"contactgroup"];
        [arry addObject:d];
    }
    [result close];
    return arry;
}

-(NSMutableArray *)queryConatctArray:(NSString *)phone{
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from contact_info where phone=?",phone];
    while ([result next]) {
        TContact *d =[[TContact alloc]init];
        d.id= [result intForColumn:@"id"];
        d.reallyId= [result stringForColumn:@"reallyId"];
        d.phone = [result stringForColumn:@"phone"];
        d.name= [result stringForColumn:@"name"];
        d.group = [result stringForColumn:@"contactgroup"];
        [arry addObject:d];
    }
    [result close];
    return arry;
}

-(void)deleteContactAll{
    BOOL flag = [_db executeUpdate:@"delete from contact_info"];
    if (flag) {
        NSLog(@"deletAllStock＝＝＝＝＝＝＝success");
    }else{
        NSLog(@"failure");
    }
}
//分组
-(NSMutableArray *)queryConatctGroupArray{
    NSMutableArray *data =[NSMutableArray array];
    NSString *doc =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES)lastObject];
    NSString *plistPath =[doc stringByAppendingPathComponent:@"contactgroup.plist"];
   NSArray *group =[NSArray arrayWithContentsOfFile:plistPath];
    NSMutableArray *dataConatct = [instance queryConatctArray];
    for (int i=0; i<group.count;i++) {
        NSMutableArray *childArr =[NSMutableArray array];
        TContactGroup *g =[[TContactGroup alloc]init];
        g.name =[group objectAtIndex:i];
        for (TContact *t in dataConatct) {
            if ([g.name isEqualToString:t.group]) {
                [childArr addObject:t];
            }
        }
        g.child=childArr;
        [data addObject:g];
    }
    return data;
}



-(void)deleteNewContactAll{
    BOOL flag = [_db executeUpdate:@"delete from new_contact_info"];
    if (flag) {
        NSLog(@"deletAllStock＝＝＝＝＝＝＝success");
    }else{
        NSLog(@"failure");
    }
}

-(void)insertNewConatctArray:(NSMutableArray *)contactArray{
    for (NewContactDao *t in contactArray) {
        BOOL flag = [_db executeUpdate:@"insert into new_contact_info (contactId,displayName,phoneNum,sortKey,photoId,lookUpKey,selected,formattedNumber,pinyin,version,note,group_id,group_name) values (?,?,?,?,?,?,?,?,?,?,?,?,?)",t.contactId,t.displayName,t.phoneNum,t.sortKey,t.photoId,t.lookUpKey,t.selected,t.formattedNumber,t.pinyin,t.version,t.note,t.group_id,t.group_name];
        if (flag) {
            NSLog(@"success");
        }else{
            NSLog(@"failure");
        }
    }
}

-(NSMutableArray *)queryNewConatctArray{
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from new_contact_info"];
    while ([result next]) {
        NewContactDao *d =[[NewContactDao alloc]init];
        d.id= [result intForColumn:@"id"];
        d.contactId= [result intForColumn:@"contactId"];
        d.displayName = [result stringForColumn:@"displayName"];
        d.phoneNum= [result stringForColumn:@"phoneNum"];
        d.sortKey = [result stringForColumn:@"sortKey"];
        
        d.photoId= [result intForColumn:@"photoId"];
        d.lookUpKey = [result stringForColumn:@"lookUpKey"];
        d.selected= [result intForColumn:@"selected"];
        d.formattedNumber = [result stringForColumn:@"formattedNumber"];
        
        d.pinyin= [result stringForColumn:@"pinyin"];
        d.version = [result stringForColumn:@"version"];
        d.note= [result stringForColumn:@"note"];
        d.group_id = [result intForColumn:@"group_id"];
        d.group_name = [result stringForColumn:@"group_name"];
        [arry addObject:d];
    }
    [result close];
    return arry;
}

-(void)deleteAllPersonInfo{
    BOOL flag = [_db executeUpdate:@"delete from person_info"];
    if (flag) {
        NSLog(@"deletAllperson_info＝＝＝＝＝＝＝success");
    }else{
        NSLog(@"failure");
    }
}
-(void)insertPersonInfoArray:(NSMutableArray *)contactArray{
    NSLog(@"====a=insertPersonInfoArray %lu",(unsigned long)contactArray.count);
    for (ContactPersonInfo *t in contactArray) {
        BOOL flag = [_db executeUpdate:@"insert into person_info (user_id,head_pic,nickname,sign,sex,other,address) values (?,?,?,?,?,?,?)",t.user_id,t.head_pic,t.nickname,t.sign,t.sex,t.other,t.address];
        if (flag) {
            NSLog(@"insertPersonInfoArray=========success");
        }else{
            NSLog(@"insertPersonInfoArray=======failure");
        }
    }
}

-(NSMutableArray *)queryPersonInfoByUserId:(NSString *)userId{
    NSMutableArray *arry = [NSMutableArray array];
    NSLog(@"userId=====%@",userId);
    FMResultSet *result =  [_db executeQuery:@"select * from person_info where user_id =?",userId];
    while ([result next]) {
        ContactPersonInfo *d =[[ContactPersonInfo alloc]init];
        //d.id= [result intForColumn:@"id"];
        d.user_id= [result stringForColumn:@"user_id"];
        d.head_pic = [result stringForColumn:@"head_pic"];
        d.nickname= [result stringForColumn:@"nickname"];
        d.sign = [result stringForColumn:@"sign"];
        d.sex = [result stringForColumn:@"sex"];
        d.other = [result stringForColumn:@"other"];
        d.address= [result stringForColumn:@"address"];
        [arry addObject:d];
    }
    [result close];
    return arry;
}
-(void)updatePersonInfo:(NSMutableArray *)contactArray{
    for (ContactPersonInfo *contact in contactArray) {
        BOOL flag = [_db executeUpdate:@"update person_info set head_pic =?,nickname=?,sign=?,sex =?,other=?,address=?where user_id=?",contact.head_pic,contact.nickname,contact.sign,contact.sex,contact.other,contact.address,contact.user_id];
        if (flag) {
            NSLog(@"success");
        }else{
            NSLog(@"failure");
        }
    }
}
-(void)insertMarkInfoArray:(NSMutableArray *)contactArray{
    NSNumber *isDelete=nil;
    NSNumber *isSendTo=nil;
    NSString *staus =@"插入";
    for (MarkInfo *t in contactArray) {
//        if (t.isDelete) {
//            isDelete =@1;
//        }else{
//            isDelete =@0;
//        }
//        if (t.isSendTo) {
//            isSendTo =@1;
//        }else{
//            isSendTo =@0;
//        }
        isDelete =@0;
        isSendTo =@0;
        BOOL flag = [_db executeUpdate:@"insert into mark_info (number,mark,staus,time,isSendTo,isDelete) values (?,?,?,?,?,?)",t.number,t.mark,staus,t.time,isSendTo,isDelete];
        
        //BOOL flag = [_db executeUpdate:@"insert into mark_info (number,mark,staus,time,isSendTo,isDelete) values (?,?,?,?,?,?)",@"",@"2",staus,@"5",isSendTo,isDelete];
        if (flag) {
            NSLog(@"success");
        }else{
            NSLog(@"failure");
        }
    }
}
//删除
-(void)deleteMarkArray:(NSMutableArray *)contactArray{
    for (MarkInfo *t in contactArray) {
        BOOL flag = [_db executeUpdate:@"delete from mark_info where number=?",t.number];
        if (flag) {
            NSLog(@"success");
        }else{
            NSLog(@"failure");
        }
    }
}
//更新标记
-(void)updateMarkInfo:(NSMutableArray *)contactArray{
    for (MarkInfo *contact in contactArray) {
        //BOOL flag = [_db executeUpdate:@"update mark_info set number=?,mark=?,staus=?,time=?,isSendTo=?,isDelete=?where id=?",contact.number,contact.mark,@"",contact.time,@0,@0,contact.id];
        NSLog(@"jdadkakdakd%@",contact.mark);
        BOOL flag = [_db executeUpdate:@"update mark_info set mark=?where number=?",contact.mark,contact.number];
        if (flag) {
            NSLog(@"success");
        }else{
            NSLog(@"failure");
        }
    }
}
-(NSMutableArray *)queryMarkArray:(NSString *)number{
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from mark_info where number =?",number];
    while ([result next]) {
        MarkInfo *d =[[MarkInfo alloc]init];
        d.id= [result intForColumn:@"id"];
        d.number =[result stringForColumn:@"number"];
        d.mark = [result stringForColumn:@"mark"];
        d.staus= [result stringForColumn:@"staus"];
        d.time = [result stringForColumn:@"time"];
        int isSendTo =[result intForColumn:@"isSendTo"];
        if (isSendTo==1) {
            d.isSendTo =YES;
        }else{
            d.isSendTo =NO;
        }
        int isDelete =[result intForColumn:@"isDelete"];
        if (isDelete==1) {
            d.isDelete =YES;
        }else{
            d.isDelete =NO;
        }
        [arry addObject:d];
    }
    [result close];
    return arry;
}
-(NSMutableArray *)queryMarkArray{
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from mark_info"];
    while ([result next]) {
        MarkInfo *d =[[MarkInfo alloc]init];
        d.id= [result intForColumn:@"id"];
        d.number =[result stringForColumn:@"number"];
        d.mark = [result stringForColumn:@"mark"];
        d.staus= [result stringForColumn:@"staus"];
       d.time = [result stringForColumn:@"time"];
        int isSendTo =[result intForColumn:@"isSendTo"];
        if (isSendTo==1) {
            d.isSendTo =YES;
        }else{
            d.isSendTo =NO;
        }
        int isDelete =[result intForColumn:@"isDelete"];
        if (isDelete==1) {
            d.isDelete =YES;
        }else{
            d.isDelete =NO;
        }
        [arry addObject:d];
    }
    [result close];
    return arry;
}
//插入
-(void)insertInterceptInfoArray:(NSMutableArray *)contactArray{
    for (InterceptInfo *t in contactArray) {
        BOOL flag = [_db executeUpdate:@"insert into intercept_info_a (callcontent,type,callFrom,callTo,mark,attribution,time,isRead) values (?,?,?,?,?,?,?,?)",t.content,t.type,t.from,t.to,t.mark,t.attribution,t.time,t.isRead];
        if (flag) {
            NSLog(@"insertInterceptInfoArray==========success");
        }else{
            NSLog(@"failure");
        }
    }
}
-(NSMutableArray *)queryCallInterceptArray{
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from intercept_info_a where type =?",@"call"];
    while ([result next]) {
        InterceptInfo *d =[[InterceptInfo alloc]init];
        d.id= [result intForColumn:@"id"];
        d.content =[result stringForColumn:@"callcontent"];
        d.type = [result stringForColumn:@"type"];
        d.from= [result stringForColumn:@"callFrom"];
        d.to = [result stringForColumn:@"callTo"];
        d.attribution= [result stringForColumn:@"attribution"];
        d.time  = [result stringForColumn:@"time"];
        d.isRead =[result stringForColumn:@"isRead"];
        d.mark=[result stringForColumn:@"mark"];
        [arry addObject:d];
    }
    [result close];
    return arry;
}

-(NSMutableArray *)querySmsInterceptArray{
    NSMutableArray *arry = [NSMutableArray array];
    FMResultSet *result =  [_db executeQuery:@"select * from intercept_info_a where type =?",@"sms"];
    while ([result next]) {
        InterceptInfo *d =[[InterceptInfo alloc]init];
        d.id= [result intForColumn:@"id"];
        d.content =[result stringForColumn:@"callcontent"];
        d.type = [result stringForColumn:@"type"];
        d.from= [result stringForColumn:@"callFrom"];
        d.to = [result stringForColumn:@"callTo"];
        d.attribution= [result stringForColumn:@"attribution"];
        d.time  = [result stringForColumn:@"time"];
        d.isRead =[result stringForColumn:@"isRead"];
        d.mark=[result stringForColumn:@"mark"];
        [arry addObject:d];
    }
    [result close];
    return arry;
}
//更新
-(void)updateInterceptInfo:(NSMutableArray *)contactArray{
    for (InterceptInfo *contact in contactArray) {
        NSNumber *Id =[NSNumber numberWithLong:contact.id];
        BOOL flag = [_db executeUpdate:@"update intercept_info_a set isRead=?where id=?",contact.isRead,Id];
        if (flag) {
            NSLog(@"success");
        }else{
            NSLog(@"failure");
        }
    }
}
-(void)deleteMarkInfoAll{
    BOOL flag = [_db executeUpdate:@"delete from mark_info"];
    if (flag) {
        NSLog(@"deletAllStock＝＝＝＝＝＝＝success");
    }else{
        NSLog(@"failure");
    }
}
@end

